<template>
  <div class="app-container">

    <div class="search-div">
      <el-form label-width="70px" size="small">
        <el-row>
          <el-col :span="4">
            <el-input style="width: 95%" v-model="searchObj.name" placeholder="卷子名称"></el-input>
          </el-col>
          <el-col :span="8">
            <el-form-item label="测试时间">
              <el-date-picker
                v-model="createTimes"
                type="datetimerange"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                value-format="yyyy-MM-dd HH:mm:ss"
                style="margin-right: 10px;width: 100%;"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="display:flex">
          <el-button type="primary" icon="el-icon-search" size="mini"  @click="fetchData()">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetData">重置</el-button>
        </el-row>
      </el-form>
    </div>


    <!-- 列表 -->
    <el-table
      v-loading="listLoading"
      :data="list"
      stripe
      border
      style="width: 100%;margin-top: 10px;">
      <el-table-column
        label="序号"
        width="50"
        align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="name" label="卷子名称"/>
      <el-table-column prop="point" label="得分"/>
      <el-table-column prop="sumScore" label="总分"/>
      <el-table-column prop="createTime" label="测试时间" />
      <el-table-column label="操作"  align="center" fixed="right" width="150">
        <template slot-scope="scope">
          <el-button type="primary" plain round :disabled="$hasBP('bnt.mywork.workdetail')  === false" icon="el-icon-document" size="mini" @click="GotoDetail(scope.row)" title="查看详情"/>
          <el-button type="warning" plain round :icon="reFreshIcon" :disabled="reFreshDisabled" size="mini" @click="reFresh(scope.row.id)" title="刷新成绩" />
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <el-pagination
      :current-page="page"
      :total="total"
      :page-size="limit"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="fetchData"
    />
  </div>
</template>
<style>
    .search-div {
        padding:10px;border: 1px solid #EBEEF5;border-radius:3px;
    }
    .tools-div {
        margin-top: 10px;padding:10px;border: 1px solid #EBEEF5;border-radius:3px;
    }
</style>
<script>
import api from '@/api/El/eluserPaper'
const defaultForm = {
  id: '',
  name: '',
  radioScore:'',
  multiScore:'',
  judgeScore:'',
  saqScore:'',
  createTime:'',
  updateTime:'',
}
export default {
  data() {
    return {
      reFreshIcon:'el-icon-refresh-right', //刷新图标展示
      reFreshDisabled : false,    //刷新是否可以点击
      listLoading: true, // 数据是否正在加载
      list: null, // banner列表
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      searchObj: {    //条件查询
        name:''
      },

      createTimes: [],

      checkAll: false, // 是否全选

      dialogVisible: false,
      Elpaper: defaultForm,

    }
  },
  // 生命周期函数：内存准备完毕，页面渲染成功
  mounted() {
    this.fetchData()
  },

  methods: {
    
    // 加载banner列表数据
    fetchData(page = 1) {
      this.page = page
      if(this.createTimes && this.createTimes.length ==2) {
        this.searchObj.createTimeBegin = this.createTimes[0]
        this.searchObj.createTimeEnd = this.createTimes[1]
      }

      api.Mywork(this.page, this.limit, this.searchObj).then(
        response => {
          this.list = response.data.records
          this.total = response.data.total

          this.list.forEach(element => {
              element.sumScore = element.radioCount * element.radioScore + element.multiCount * element.multiScore + element.judgeCount * element.judgeScore + element.saqCount * element.saqScore
          });
          // 数据加载并绑定成功
          this.listLoading = false
        }
      )

    },
    //刷新信息
    reFresh(id){
        this.reFreshIcon = "el-icon-loading"
        this.reFreshDisabled = true
        api.UpdatePoint(id).then(resp => {
            this.$message.success('刷新成功')
            this.reFreshIcon = "el-icon-refresh-right"
            this.reFreshDisabled = false
            this.fetchData(this.page)
        })
    },
    // 重置查询表单
    resetData() {
      this.searchObj = {}
      this.createTimes = []
      this.fetchData()
    },

      //去详情页
      GotoDetail(row){
        this.$router.push('/work/workDetail?id='+row.id);
      }
  }
}
</script>